package com.ruoyi.web.controller.custom;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RnxInviteLog;
import com.ruoyi.system.service.IRnxInviteLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 邀请记录Controller
 * 
 * @author ruoyi
 * @date 2022-05-06
 */
@Controller
@RequestMapping("/system/log")
public class RnxInviteLogController extends BaseController
{
    private String prefix = "rnx/invite";

    @Autowired
    private IRnxInviteLogService rnxInviteLogService;

    @RequiresPermissions("system:log:view")
    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    /**
     * 查询邀请记录列表
     */
    @RequiresPermissions("system:log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RnxInviteLog rnxInviteLog)
    {
        startPage();
        List<RnxInviteLog> list = rnxInviteLogService.selectRnxInviteLogList(rnxInviteLog);
        return getDataTable(list);
    }

    /**
     * 导出邀请记录列表
     */
    @RequiresPermissions("system:log:export")
    @Log(title = "邀请记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RnxInviteLog rnxInviteLog)
    {
        List<RnxInviteLog> list = rnxInviteLogService.selectRnxInviteLogList(rnxInviteLog);
        ExcelUtil<RnxInviteLog> util = new ExcelUtil<RnxInviteLog>(RnxInviteLog.class);
        return util.exportExcel(list, "邀请记录数据");
    }

    /**
     * 新增邀请记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存邀请记录
     */
    @RequiresPermissions("system:log:add")
    @Log(title = "邀请记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RnxInviteLog rnxInviteLog)
    {
        return toAjax(rnxInviteLogService.insertRnxInviteLog(rnxInviteLog));
    }

    /**
     * 修改邀请记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RnxInviteLog rnxInviteLog = rnxInviteLogService.selectRnxInviteLogById(id);
        mmap.put("rnxInviteLog", rnxInviteLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存邀请记录
     */
    @RequiresPermissions("system:log:edit")
    @Log(title = "邀请记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RnxInviteLog rnxInviteLog)
    {
        return toAjax(rnxInviteLogService.updateRnxInviteLog(rnxInviteLog));
    }

    /**
     * 删除邀请记录
     */
    @RequiresPermissions("system:log:remove")
    @Log(title = "邀请记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rnxInviteLogService.deleteRnxInviteLogByIds(ids));
    }
}
